﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FilesDirectory
{
    class Program
    {
        static void Main(string[] args)
        {
            string newStr = @"D:\Programming\С#\Training_CodPlex\Inteducation\mvdovare\FilesDirectory\FilesDirectory\FileResources\NewFolder";
            Directory.CreateDirectory(newStr);

            string[] files = Directory.GetFiles(@"D:\Programming\С#\Training_CodPlex\Inteducation\mvdovare\FilesDirectory\FilesDirectory\FileResources\NewFolder", "*.txt", 
                SearchOption.TopDirectoryOnly);

            string filePath = @"D:\Programming\С#\Training_CodPlex\Inteducation\mvdovare\FilesDirectory\FilesDirectory\FileResources\NewFolder\HT.txt";

            if (Directory.Exists(newStr))
            {


                string files2 = File.ReadAllText(filePath);
                Console.WriteLine(files2);
                files2 = files2.Replace("\r\n\r\n", " ");
                string[] filesresult = files2.Split(' ');
                int wordCount = filesresult.Length;
                Console.WriteLine();

                string longestWord = "";

                foreach (var word in filesresult)
                {
                    if (word.Trim(',', '.', '(', ')').Length >= longestWord.Length)
                    {
                        longestWord = word.Trim(',', '.', '(', ')');
                    }
                    else
                    {
                        continue;
                    }
                }
                Console.WriteLine("Amount of words is - {0}.\nThe longest word is - \"{1}\" with length - {2} letters.", wordCount, longestWord, longestWord.Length);
                
                
                //}

                //bool isDirectoryExist = Directory.Exists(@"D:\Programming\С#\Training_CodPlex\Inteducation\mvdovare\FilesDirectory\FilesDirectory\FileResources\NewFolder");

                //if (isDirectoryExist)
                //{
                //    Directory.Delete(@"D:\Programming\С#\Training_CodPlex\Inteducation\mvdovare\FilesDirectory\FilesDirectory\FileResources\NewFolder", true);
                //}


                //string files2 = Directory.GetFiles(newStr, "HT.txt", SearchOption.TopDirectoryOnly);

            }
        }
    }
}
